// 快速排序
var array = [5, 6, 4, 2, 3, 1, 0]

function sort (arr) {
  if (arr.length <= 1) {
    return arr
  }
  var middleIdx = Math.floor(arr.length / 2)
  var ruler = arr.splice(middleIdx, 1)[0]
  var left = []
  var right = []
  for(var i = 0; i < arr.length; i++) {
    if (arr[i] < ruler) {
      left.push(arr[i])
    } else {
      right.push(arr[i])
    }
  }

  return sort(left).concat([ruler], sort(right))
}

var re = sort(array)
console.log('result', re)